package action;

import java.util.HashMap;
import java.util.List;

import model.Businessdict;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.github.miemiedev.mybatis.paginator.domain.PageList;

import service.BusiDictService;
import action.base.BaseAction;

@Controller
@Scope("prototype")
public class BusiDictAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Autowired
	private BusiDictService busiDictService;
	private boolean success = false;
	private Businessdict businessdict;
	private PageList<HashMap<String, Object>> pageList;
	private List<Businessdict> list;
	private int total;

	public String queryPage() {
		Integer typeid = super.getParameterInt("typeid");
		int limit = super.getParameterInt("limit");
		int page = super.getParameterInt("page");
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("typeid", typeid);
		pageList = busiDictService.queryPage(page, limit, map);
		setTotal(pageList.getPaginator().getTotalCount());
		return "queryPage";

	}

	public String saveOrUpdate() {
		busiDictService.saveOrUpdate(businessdict);
		success = true;
		return "success";
	}

	public String delete() {
		String ids = super.getParameterStr("ids");
		busiDictService.delete(ids);
		success = true;
		return "success";
	}

	public String getByType() {
		String type = super.getParameterStr("type");
		String flag = super.getParameterStr("flag");
		list = busiDictService.getByType(type);
		if (StringUtils.isNotBlank(flag) && flag.equals("search")) {
			Businessdict bd = new Businessdict();
			bd.setId(0);
			bd.setName("全部");
			list.add(bd);
		}
		success = true;
		return "list";
	}

	public BusiDictService getBusiDictService() {
		return busiDictService;
	}

	public void setBusiDictService(BusiDictService busiDictService) {
		this.busiDictService = busiDictService;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public Businessdict getBusinessdict() {
		return businessdict;
	}

	public void setBusinessdict(Businessdict businessdict) {
		this.businessdict = businessdict;
	}

	public PageList<HashMap<String, Object>> getPageList() {
		return pageList;
	}

	public void setPageList(PageList<HashMap<String, Object>> pageList) {
		this.pageList = pageList;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public List<Businessdict> getList() {
		return list;
	}

	public void setList(List<Businessdict> list) {
		this.list = list;
	}

}
